package cn.servlet;

import cn.dao.UserDao;
import cn.dao.UserDaoImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req,
                           HttpServletResponse resp)
            throws IOException {
        req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        UserDao userDao = new UserDaoImpl();
        boolean flag = userDao.register(username, password);
        System.out.println(flag);
        if (!flag) {
            resp.sendRedirect("fail.jsp");
        } else {
            resp.sendRedirect("login.jsp");
        }
    }
}
